package com.house.java.util;

import java.sql.Date;

import com.house.java.model.News;
import com.sun.xml.internal.bind.v2.model.core.ID;

public class NewsUtils {

	public void setNews(News news,String fieldName,String fieldValue){
		if(StringUtils.hasLength(fieldValue) && StringUtils.hasLength(fieldName)){
			setFieldForNews(news, fieldName, fieldValue);
		}
	}
	
	/**
	 * 根据属性名设置NewHouse的属性值
	 * @param house
	 */
	public void setFieldForNews(News news,String fieldName,String fieldValue){
		if(fieldName.equals("title")){
			news.setTitle(fieldValue);
		}else if (fieldName.equals("id")) {
			news.setId(Long.valueOf(fieldValue));
		}else if (fieldName.equals("author")) {
			news.setAuthor(fieldValue);
		}else if (fieldName.equals("source")) {
			news.setSource(fieldValue);
		}else if (fieldName.equals("mainCategory")) {
			news.setMainCategory(Integer.parseInt(fieldValue));
		}else if (fieldName.equals("secondCategory")) {
			news.setSecondCategory(Integer.parseInt(fieldValue));
		}else if (fieldName.equals("countryCode")) {
			news.setCountryCode(Integer.parseInt(fieldValue));
		}else if (fieldName.equals("provinceCode")) {
			news.setProvinceCode(Integer.parseInt(fieldValue));
		}else if (fieldName.equals("cityCode")) {
			news.setCityCode(Integer.parseInt(fieldValue));
		}else if (fieldName.equals("date")) {
			news.setDate(Date.valueOf(fieldValue));
		}else if (fieldName.equals("digest")) {
			news.setDigest(fieldValue);
		}else if (fieldName.equals("body")) {
			news.setBody(fieldValue);
		}else if (fieldName.equals("images")) {
			fieldValue = StringUtils.hasLength(news.getImages())?(news.getImages()+StringUtils.semicolon+fieldValue):fieldValue;
			news.setImages(fieldValue);
		}
	}
}
